<%@ page language="java" import="java.io.*" %>
<%!
    int count = 0;
    String dbPath = "G:\\2.txt";

    public void jspInit() {
        try {
            FileInputStream fileInputStream = new FileInputStream(dbPath);
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
            String s = bufferedReader.readLine();
            count = Integer.parseInt(s);
            fileInputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
            count = 0;
        }

    }
%>
<%--下面是向浏览器输出的主要内容，
它将成为产生的_jspService()方法的一部分
--%>
<html>
<body>
<% count++; %>
Welcome! You are <b><%=count%>
</b>th visitor(s).
</body>
</html>
<%!
    public void jspDestroy() {

        try {
            OutputStream bufferedWriter = new FileOutputStream(dbPath);
            bufferedWriter.write(String.valueOf(count).getBytes());
            bufferedWriter.flush();
            bufferedWriter.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
%>
